<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/02/xpath-functions">
    <xsl:param name="DOTNET2"/>
    
  <xsl:template name="replace-string">
    <xsl:param name="text"/>
    <xsl:param name="replace"/>
    <xsl:param name="with"/>
    <xsl:choose>
      <xsl:when test="contains($text,$replace)">
        <xsl:value-of select="substring-before($text,$replace)"/>
        <xsl:value-of select="$with"/>
        <xsl:call-template name="replace-string">
          <xsl:with-param name="text" select="substring-after($text,$replace)"/>
          <xsl:with-param name="replace" select="$replace"/>
          <xsl:with-param name="with" select="$with"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$text"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  
  
	<xsl:template match="Class"><xsl:variable name="Name" select="Name"/>
        <xsl:variable name="HeaderInfo" select="HeaderInfo/ProjectName"/>

// ***************************************************************
// Automatically generated from CodeGen2007 
// Project Name: <xsl:value-of select="HeaderInfo/ProjectName"/>
// Prefix: <xsl:value-of select="HeaderInfo/Prefix"/>
// ***************************************************************

#define PARAMFULL



using System;
using System.Xml;
using System.Xml.Serialization;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

namespace <xsl:value-of select="HeaderInfo/ProjectName"/>.DataObject  {


	[ Serializable ]
	<xsl:for-each select="ClassAttribs/ClassAttributes">
	<xsl:if test="KnownClass='true'">
	[ XmlInclude ( typeof(<xsl:value-of select="Type"/> ) ) ]<xsl:text>&#xD;&#9;</xsl:text>
	</xsl:if>
	</xsl:for-each>
	public class <xsl:value-of select="Name"/> : <xsl:value-of select="HeaderInfo/ProjectName"/>DataObject, IComparable {
		
		public <xsl:value-of select="Name"/> () : base() { }
			
		public <xsl:value-of select="Name"/> ( Guid objectID ) : this () {
			Load ( objectID );
		}
		
		public <xsl:value-of select="Name"/> ( Guid objectID , bool audit ) : this () {
			Load ( objectID , audit );
		}
		
		public <xsl:value-of select="Name"/> ( Guid objectID,
		    int timezoneOffset ) : this( timezoneOffset ) {
				Load ( objectID );
		}
		
		
		
		// timezone specific constructor
		public <xsl:value-of select="Name"/> ( int timezoneOffset ) 
			    : base( timezoneOffset ) {
		
		}
		
		
		protected override void SetThisFromInstance ( <xsl:value-of select="HeaderInfo/ProjectName"/>DataObject u ) 
		{
			<xsl:value-of select="Name"/> local = ( <xsl:value-of select="Name"/> ) u;
			
			<xsl:for-each select="ClassAttribs/ClassAttributes">
				<xsl:value-of select="Name"/> = local.<xsl:value-of select="Name"/>;
			</xsl:for-each>
		
			objectID = local.objectID;
			createdDate = local.createdDate;
			modifiedDate = local.modifiedDate;
		}
		
		private static <xsl:value-of select="Name"/> getObject ( SqlDataReader sqlDr )
		{
		<xsl:value-of select="Name"/> _<xsl:value-of select="Name"/> = new <xsl:value-of select="Name"/> ();
								_<xsl:value-of select="Name"/>.ObjectID = (Guid) sqlDr [ "<xsl:value-of select="Name"/>ID" ];
								_<xsl:value-of select="Name"/>.setDefaults ( _<xsl:value-of select="Name"/> , sqlDr );
				
				
				<xsl:for-each select="ClassAttribs/ClassAttributes">
				    <xsl:if test="CType='single'">
					<xsl:if test="KnownClass='false'">
					    <xsl:if test="Type!='bool'">
								_<xsl:value-of select="$Name"/>.<xsl:value-of select="Name"/> = ( <xsl:value-of select="Type"/> ) sqlDr[ "<xsl:value-of select="Name"/>" ];
					    </xsl:if>          
					    
					    <xsl:if test="Type='bool'">
								_<xsl:value-of select="$Name"/>.<xsl:value-of select="Name"/> = ( bool ) ( ( ( byte ) sqlDr[ "<xsl:value-of select="Name"/>" ] ) == 1 );
					    </xsl:if>
					</xsl:if>
					<xsl:if test="KnownClass='true'">
					    //_<xsl:value-of select="$Name"/>.<xsl:value-of select="Name"/> = new <xsl:value-of select="Type"/> ( ( Guid ) sqlDr[ "<xsl:value-of select="Name"/>" ] );
						_<xsl:value-of select="$Name"/>.__<xsl:value-of select="Name"/> = ( Guid ) sqlDr[ "<xsl:value-of select="Name"/>" ];
					</xsl:if>
					<xsl:text>&#xD;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;</xsl:text> 
				    </xsl:if>
				    
								</xsl:for-each>
								
			return _<xsl:value-of select="Name"/>;
		}
		
		
		
		public int SelectCount ()
		{
			return SelectCount ( string.Empty );
		}
		
		
		public override <xsl:value-of select="HeaderInfo/ProjectName"/>DataObject LoadSingle ( Guid objectID )
		{
			return ( <xsl:value-of select="HeaderInfo/ProjectName"/>DataObject ) 
				new <xsl:value-of select="Name"/> ( objectID );
		}
		
		
	
		public int SelectCount ( string filter )
		{
			int resultCount = 0;
			try
			{
				using( SqlConnection sqlCon=new SqlConnection( <xsl:value-of select="HeaderInfo/ProjectName"/>DataObject.GetDB () ) ) {
					sqlCon.Open ();
					using ( SqlCommand sqlCom = new SqlCommand ( "SELECT COUNT(<xsl:value-of select="Name"/>ID) FROM [<xsl:value-of select="Name"/>] " + (filter.Equals ( string.Empty ) ? "" : "WHERE ") + filter , sqlCon ) )
					{
						sqlCom.CommandTimeout = 120;
						resultCount = (int) sqlCom.ExecuteScalar ();
					}
					sqlCon.Close ();
				}
			
			}
			catch ( Exception ex )
			{
				<xsl:value-of select="HeaderInfo/ProjectName"/>DataObject.ReportException ( ex );
			}
			
			return resultCount;
		}
		
		public <xsl:value-of select="Name"/>[] Get ( int max , int start )
		{
			return Select ( string.Empty , string.Empty , max , start );
		}
		
		public <xsl:value-of select="Name"/>[] Get ( string filter , int max , int start )
		{
			return Select ( filter , string.Empty , max , start );
		}
		
		
		
		public <xsl:value-of select="Name"/>[] Select ( string filter , string sort , int max , int start )
		{
			int pageSize = max;
			int pageNumber = start == 0 ? 1 : ( start / max ) + 1 ;
		
			ArrayList alResults = new ArrayList ();
			try 
			{
				
				using( SqlConnection sqlCon=new SqlConnection( <xsl:value-of select="HeaderInfo/ProjectName"/>DataObject.GetDB () ) ) {
					sqlCon.Open ();
					using ( SqlCommand sqlCom = new SqlCommand ( "Paging_RowCount" , sqlCon ) ) {
						sqlCom.CommandTimeout = 120;
						sqlCom.CommandType = CommandType.StoredProcedure;
						sqlCom.Parameters.Add ( "@Tables", "<xsl:value-of select="Name"/>" );
						sqlCom.Parameters.Add ( "@PK", "<xsl:value-of select="Name"/>Id" );
						sqlCom.Parameters.Add ( "@Fields", "<xsl:value-of select="Name"/>Id" );
						sqlCom.Parameters.Add ( "@Filter", filter );
						sqlCom.Parameters.Add ( "@PageNumber", pageNumber );
						sqlCom.Parameters.Add ( "@PageSize", pageSize );
						sqlCom.Parameters.Add ( "@Sort", sort );
						
						using ( SqlDataReader sqlDr = sqlCom.ExecuteReader () )
						{
							while ( sqlDr.Read () )
							{
								alResults.Add ( getObject ( sqlDr ) );
							}
						}
					}
					sqlCon.Close ();
				}
			}
			catch ( Exception ex ) 
			{
				<xsl:value-of select="HeaderInfo/ProjectName"/>DataObject.ReportException ( ex );
			}
			
			return ( <xsl:value-of select="Name"/>[] ) alResults.ToArray ( typeof ( <xsl:value-of select="Name"/> ) );
		}
		

		public static <xsl:value-of select="Name"/>[] LoadUsingFullSQL ( string query )
		{
			if ( IsInfected ( query ) ) throw new Exception ( "Potential SQL Injection Attack" );
			ArrayList alResults = new ArrayList ();
			try 
			{
				using( SqlConnection sqlCon=new SqlConnection( <xsl:value-of select="HeaderInfo/ProjectName"/>DataObject.GetDB () ) ) {
					sqlCon.Open ();
					using ( SqlCommand sqlCom = new SqlCommand ( query , sqlCon ) ) {
						sqlCom.CommandTimeout = 120;
						using ( SqlDataReader sqlDr = sqlCom.ExecuteReader () )
						{
							
							while ( sqlDr.Read () )
							{
								if ( sqlDr.FieldCount &gt; 1 )
									alResults.Add ( getObject ( sqlDr ) );
								else {
									alResults.Add ( new <xsl:value-of select="Name"/> ( sqlDr.GetGuid ( 0 ) ) );
								}
							}
						}
					
					}
				}
			
			
			}
			catch ( Exception ex )
			{
				<xsl:value-of select="HeaderInfo/ProjectName"/>DataObject.ReportException ( ex );
				
				throw ex;
			}
			
			return ( <xsl:value-of select="Name"/> [] ) alResults.ToArray ( typeof ( <xsl:value-of select="Name"/> ) );
		
		}
		
		public static <xsl:value-of select="Name"/>[] LoadUsingSQL ( string query )
		{
			if ( IsInfected ( query ) ) throw new Exception ( "Potential SQL Injection Attack" );
			ArrayList alResults = new ArrayList ();
			try 
			{
				using( SqlConnection sqlCon=new SqlConnection( <xsl:value-of select="HeaderInfo/ProjectName"/>DataObject.GetDB () ) ) {
					sqlCon.Open ();
					using ( SqlCommand sqlCom = new SqlCommand ( "SELECT * FROM [<xsl:value-of select="Name"/>] " +
					(query.Equals ( String.Empty ) ? "" : "WHERE ") + query , sqlCon ) ) {
						sqlCom.CommandTimeout = 120;
						using ( SqlDataReader sqlDr = sqlCom.ExecuteReader () )
						{
							while ( sqlDr.Read () )
							{
								alResults.Add ( getObject ( sqlDr ) );
							}
						}
					
					}
				}
			
			
			}
			catch ( Exception ex )
			{
				<xsl:value-of select="HeaderInfo/ProjectName"/>DataObject.ReportException ( ex );
				
				throw ex;
			}
			
			return ( <xsl:value-of select="Name"/> [] ) alResults.ToArray ( typeof ( <xsl:value-of select="Name"/> ) );
		
		}
		
				
		
		
		public override bool Load ( Guid objectID , bool audit ) {
			bool isRead=false;
			try {
				base.ObjectID=objectID;
				using( SqlConnection sqlCon=new SqlConnection( <xsl:value-of select="HeaderInfo/ProjectName"/>DataObject.GetDB () ) ) {
					sqlCon.Open ();
					using ( SqlCommand sqlCom = new SqlCommand ( "GENSP_<xsl:value-of select="HeaderInfo/Prefix"/>_<xsl:value-of select="Name"/>Select" + (audit?"_Audit":string.Empty), sqlCon ) ) {
						sqlCom.CommandTimeout = 120;
						sqlCom.CommandType = CommandType.StoredProcedure;
						sqlCom.Parameters.Add ( "@<xsl:value-of select="Name"/>ID" ,base.ObjectID );
						using ( SqlDataReader sqlDr = sqlCom.ExecuteReader () ) 
						{
							if ( isRead = sqlDr.Read () ) 
							{
								<xsl:value-of select="Name"/> _<xsl:value-of select="Name"/> = new <xsl:value-of select="Name"/> ();
								ObjectID = (Guid) sqlDr [ "<xsl:value-of select="Name"/>ID" ];
								base.setDefaults ( this , sqlDr );
				
				
				
				
				<xsl:for-each select="ClassAttribs/ClassAttributes">
				    <xsl:if test="CType='single'">
					<xsl:if test="KnownClass='false'">
					    <xsl:if test="Type!='bool'">
								<xsl:value-of select="Name"/> = ( <xsl:value-of select="Type"/> ) sqlDr[ "<xsl:value-of select="Name"/>" ];
					    </xsl:if>          
					    
					    <xsl:if test="Type='bool'">
								<xsl:value-of select="Name"/> = ( bool ) ( ( ( byte ) sqlDr[ "<xsl:value-of select="Name"/>" ] ) == 1 );
					    </xsl:if>
					</xsl:if>
					<xsl:if test="KnownClass='true'">
					    //<xsl:value-of select="Name"/> = new <xsl:value-of select="Type"/> ( ( Guid ) sqlDr[ "<xsl:value-of select="Name"/>" ] );
						_<xsl:value-of select="$Name"/>.__<xsl:value-of select="Name"/> = ( Guid ) sqlDr[ "<xsl:value-of select="Name"/>" ];
					</xsl:if>
					<xsl:text>&#xD;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;</xsl:text> 
				    </xsl:if>
				    
								</xsl:for-each>
								}							
						}
					}
					sqlCon.Close ();
				}
			} catch ( Exception ex ) {
				<xsl:value-of select="HeaderInfo/ProjectName"/>DataObject.ReportException ( ex );
			}
			

			if ( System.Web.HttpContext.Current!=null ) if ( isRead &amp;&amp; ! SessionState.session.ContainsKey ( objectID ) ) SessionState.session.Add ( objectID , this );

			return isRead;	
		}
		
		
		protected override bool isLatest ( System.Data.SqlClient.SqlConnection sqlCon )
		{
			DateTime modified = DateTime.Now;
			try 
			{
				using ( SqlCommand sqlCom = new SqlCommand ( "SELECT modified FROM [<xsl:value-of select="Name"/>] " +
					" WHERE <xsl:value-of select="Name"/>Id = '" + this.ObjectID + "'" ) )
				{
					sqlCom.CommandTimeout = 120;
					modified = ( DateTime ) sqlCom.ExecuteScalar ();
				}			
			
			}
			catch ( Exception ex )
			{
				<xsl:value-of select="HeaderInfo/ProjectName"/>DataObject.ReportException ( ex );
			}
			
			return modified == this.modifiedDate;
		}
		
		
		protected override bool insert ( System.Data.SqlClient.SqlConnection sqlCon )
		{
			return insert ( sqlCon , false );
		}
		
		protected override bool insert ( System.Data.SqlClient.SqlConnection sqlCon , bool isAudit ) {
			int retVal = 0;
			try {
				using ( SqlCommand sqlCom = new SqlCommand ( 
					"GENSP_<xsl:value-of select="HeaderInfo/Prefix"/>_<xsl:value-of select="Name"/>Insert" + 
					(isAudit?"_Audit":"") , sqlCon ) ) 
				{
					sqlCom.CommandTimeout = 120;
					sqlCom.CommandType = CommandType.StoredProcedure;
					sqlCom.Parameters.Add ( "@<xsl:value-of select="Name"/>ID" , base.ObjectID );
					<xsl:for-each select="ClassAttribs/ClassAttributes">
					<xsl:if test="CType='single'">
					<xsl:if test="KnownClass='false'">sqlCom.Parameters.Add ( 
						"@<xsl:value-of select="Name"/>" , this.<xsl:value-of select="Name"/> );</xsl:if>
					<xsl:if test="KnownClass='true'">sqlCom.Parameters.Add ( "@<xsl:value-of select="Name"/>" , 
					this.<xsl:value-of select="Name"/>.ObjectID );</xsl:if>
					</xsl:if><xsl:text>&#xD;&#9;&#9;&#9;&#9;&#9;</xsl:text> 
					</xsl:for-each>
					retVal = sqlCom.ExecuteNonQuery ();
				}
				
				
			} catch ( Exception ex ) {
				<xsl:value-of select="HeaderInfo/ProjectName"/>DataObject.ReportException ( ex );
				return false;
			}
			
			return retVal > 0;
		}
		
		protected override bool update(System.Data.SqlClient.SqlConnection sqlCon) {
			int retVal=0;
			try {
				using(SqlCommand sqlCom=new SqlCommand("GENSP_<xsl:value-of select="HeaderInfo/Prefix"/>_<xsl:value-of select="Name"/>Update",sqlCon)) {
					sqlCom.CommandTimeout = 120;
					sqlCom.CommandType=CommandType.StoredProcedure;
					sqlCom.Parameters.Add("@<xsl:value-of select="Name"/>ID",base.ObjectID);
					<xsl:for-each select="ClassAttribs/ClassAttributes">
					<xsl:if test="CType='single'">
					<xsl:if test="KnownClass='false'">sqlCom.Parameters.Add("@<xsl:value-of select="Name"/>",this.<xsl:value-of select="Name"/>);</xsl:if>
					<xsl:if test="KnownClass='true'">sqlCom.Parameters.Add("@<xsl:value-of select="Name"/>",this.<xsl:value-of select="Name"/>.ObjectID);</xsl:if>
					</xsl:if><xsl:text>&#xD;&#9;&#9;&#9;&#9;&#9;</xsl:text> 
					</xsl:for-each>
					retVal=sqlCom.ExecuteNonQuery();
				}
				
			} catch(Exception ex) {
				<xsl:value-of select="HeaderInfo/ProjectName"/>DataObject.ReportException(ex);
				return false;
			}
			
			
			return retVal>0;
		}
		
		
		public override bool delete() {
			int retVal=0;
			try {
				using(SqlConnection sqlCon=new SqlConnection(<xsl:value-of select="HeaderInfo/ProjectName"/>DataObject.GetDB())) {
					sqlCon.Open();
					using(SqlCommand sqlCom=new SqlCommand("GENSP_<xsl:value-of select="HeaderInfo/Prefix"/>_<xsl:value-of select="Name"/>Delete",sqlCon)) {
						sqlCom.CommandTimeout = 120;
						sqlCom.CommandType=CommandType.StoredProcedure;
						sqlCom.Parameters.Add("@<xsl:value-of select="Name"/>ID",base.ObjectID);
						retVal=sqlCom.ExecuteNonQuery();
					}
					
					
					
					sqlCon.Close();
				}
			} catch(Exception ex) {
				<xsl:value-of select="HeaderInfo/ProjectName"/>DataObject.ReportException(ex);
				return false;
			}
			
			
			return retVal>0;
		}
		
		// this returns the amount of items in the database
		public static int GetCount() {
			int returnValues=0;
			try {
				using(SqlConnection sqlCon=new SqlConnection(<xsl:value-of select="HeaderInfo/ProjectName"/>DataObject.GetDB())) {
					sqlCon.Open();
					using(SqlCommand sqlCom=new SqlCommand("GENSP_<xsl:value-of select="HeaderInfo/Prefix"/>_<xsl:value-of select="Name"/>CountAll",sqlCon)) {
						sqlCom.CommandTimeout = 120;
						sqlCom.CommandType=CommandType.StoredProcedure;
						returnValues=(int)sqlCom.ExecuteScalar();
					}
					sqlCon.Close();
				}				
			} catch(Exception ex) {
				<xsl:value-of select="HeaderInfo/ProjectName"/>DataObject.ReportException(ex);
			}	
			return returnValues;
		}
		
		
		// this returns all of the instances of <xsl:value-of select="Name"/> from the database
		public static <xsl:value-of select="Name"/>[] Get() {
			ArrayList al<xsl:value-of select="Name"/>=new ArrayList();
			try {
				using(SqlConnection sqlCon=new SqlConnection(<xsl:value-of select="HeaderInfo/ProjectName"/>DataObject.GetDB())) {
					sqlCon.Open();
					using(SqlCommand sqlCom=new SqlCommand("GENSP_<xsl:value-of select="HeaderInfo/Prefix"/>_<xsl:value-of select="Name"/>SelectAll",sqlCon)) {
						sqlCom.CommandTimeout = 120;
						sqlCom.CommandType=CommandType.StoredProcedure;
						using(SqlDataReader sqlDr=sqlCom.ExecuteReader()) {
							while(sqlDr.Read()) {
								al<xsl:value-of select="Name"/>.Add ( getObject ( sqlDr ) );
							}
						}
					}
					sqlCon.Close();
				}
			
			} catch(Exception ex) {
				<xsl:value-of select="HeaderInfo/ProjectName"/>DataObject.ReportException(ex);
			}	
			return (<xsl:value-of select="Name"/>[])al<xsl:value-of select="Name"/>.ToArray(typeof(<xsl:value-of select="Name"/>));
		}
		
		
		public static int CountGet() {
			int x=0;
			try {
				using(SqlConnection sqlCon=new SqlConnection(<xsl:value-of select="HeaderInfo/ProjectName"/>DataObject.GetDB())) {
					sqlCon.Open();
					
					using(SqlCommand sqlCom=new SqlCommand("select count(*) from [<xsl:value-of select="Name"/>]",sqlCon)) {
						sqlCom.CommandTimeout = 120;
						x = (int)sqlCom.ExecuteScalar();
					}
					sqlCon.Close();
				}
			
			} catch(Exception ex) {
				<xsl:value-of select="HeaderInfo/ProjectName"/>DataObject.ReportException(ex);
			}	
			return x;
		}
		
        <xsl:for-each  select="ClassAttribs/ClassAttributes[ToString='true']">
        protected override Guid[] Get_ToString(object val) {
            ArrayList al<xsl:value-of select="$Name"/>=new ArrayList();
            try {
                using(SqlConnection sqlCon=new SqlConnection(<xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.GetDB())) {
                    sqlCon.Open();
                    using(SqlCommand sqlCom=new SqlCommand("GENSP_<xsl:value-of select="//HeaderInfo/Prefix"/>_<xsl:value-of select="$Name"/>_<xsl:value-of select="Name"/>",sqlCon)) {
                        sqlCom.CommandTimeout = 120;
						sqlCom.CommandType=CommandType.StoredProcedure;
                        sqlCom.Parameters.Add("@val",val.ToString());
                        using(SqlDataReader sqlDr=sqlCom.ExecuteReader()) {
                            while(sqlDr.Read()) {
                                al<xsl:value-of select="$Name"/>.Add ( getObject ( sqlDr ) );
                            }
                        }
                    
                    }
                
                    sqlCon.Close();
                }
            }
            catch(Exception ex) {
                <xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.ReportException(ex);
            }
            return (Guid[])al<xsl:value-of select="$Name"/>.ToArray(typeof(Guid));
        }   
        </xsl:for-each>
        
        
        <xsl:if test="count(ClassAttribs/ClassAttributes[ToString='true'])=0">
            
        // this needs to exist because the SaveNoDupe() method requires it
        protected override Guid[] Get_ToString(object val) {
            return new Guid[0];
        }
            
        </xsl:if>
        
        
        
        #if(PARAMFULL)
        <xsl:for-each select="ClassAttribs/ClassAttributes">

            <xsl:if test="CType='single'">

                <xsl:choose>
                    <xsl:when test="Type='bool'">
        public static <xsl:value-of select="$Name"/>[] Get_<xsl:value-of select="PropertyName"/>(bool val) {
            ArrayList al<xsl:value-of select="$Name"/>=new ArrayList();
            try {
                using(SqlConnection sqlCon=new SqlConnection(<xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.GetDB())) {
                    sqlCon.Open();
                    using(SqlCommand sqlCom=new SqlCommand("GENSP_<xsl:value-of select="//HeaderInfo/Prefix"/>_<xsl:value-of select="$Name"/>_<xsl:value-of select="Name"/>",sqlCon)) {
                        sqlCom.CommandTimeout = 120;
						sqlCom.CommandType=CommandType.StoredProcedure;
                        sqlCom.Parameters.Add("@val",val?1:0);
                        using(SqlDataReader sqlDr=sqlCom.ExecuteReader()) {
                            while(sqlDr.Read()) {
                                al<xsl:value-of select="$Name"/>.Add ( getObject ( sqlDr ) );
                            }
                        }
                    
                    }
                
                    sqlCon.Close();
                }
            }
            catch(Exception ex) {
                <xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.ReportException(ex);
            }
            return (<xsl:value-of select="$Name"/>[])al<xsl:value-of select="$Name"/>.ToArray(typeof(<xsl:value-of select="$Name"/>));
        }
                    </xsl:when>
                    
                    <xsl:when test="Type='DateTime'">
        // Get when date time equals
        public static <xsl:value-of select="$Name"/>[] Get_<xsl:value-of select="PropertyName"/>(DateTime val) {
            ArrayList al<xsl:value-of select="$Name"/>=new ArrayList();
            try {
                using(SqlConnection sqlCon=new SqlConnection(<xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.GetDB())) {
                    sqlCon.Open();
                    using(SqlCommand sqlCom=new SqlCommand("GENSP_<xsl:value-of select="//HeaderInfo/Prefix"/>_<xsl:value-of select="$Name"/>_<xsl:value-of select="Name"/>",sqlCon)) {
                        sqlCom.CommandTimeout = 120;
						sqlCom.CommandType=CommandType.StoredProcedure;
                        sqlCom.Parameters.Add("@val",val);
                        using(SqlDataReader sqlDr=sqlCom.ExecuteReader()) {
                            while(sqlDr.Read()) {
                                al<xsl:value-of select="$Name"/>.Add( getObject ( sqlDr ) );
                            }
                        }
                    
                    }
                
                    sqlCon.Close();
                }
            }
            catch(Exception ex) {
                <xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.ReportException(ex);
            }
            return (<xsl:value-of select="$Name"/>[])al<xsl:value-of select="$Name"/>.ToArray(typeof(<xsl:value-of select="$Name"/>));
        }


        // Get when datetime is Before
        public static <xsl:value-of select="$Name"/>[] Get_<xsl:value-of select="PropertyName"/>_Before(DateTime val) {
            ArrayList al<xsl:value-of select="$Name"/>=new ArrayList();
            try {
                using(SqlConnection sqlCon=new SqlConnection(<xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.GetDB())) {
                    sqlCon.Open();
                    using(SqlCommand sqlCom=new SqlCommand("GENSP_<xsl:value-of select="//HeaderInfo/Prefix"/>_<xsl:value-of select="$Name"/>_<xsl:value-of select="Name"/>_Before",sqlCon)) {
                        sqlCom.CommandTimeout = 120;
						sqlCom.CommandType=CommandType.StoredProcedure;
                        sqlCom.Parameters.Add("@val",val);
                        using(SqlDataReader sqlDr=sqlCom.ExecuteReader()) {
                            while(sqlDr.Read()) {
                                al<xsl:value-of select="$Name"/>.Add ( getObject ( sqlDr ) );
                            }
                        }
                    
                    }
                
                    sqlCon.Close();
                }
            }
            catch(Exception ex) {
                <xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.ReportException(ex);
            }
            return (<xsl:value-of select="$Name"/>[])al<xsl:value-of select="$Name"/>.ToArray(typeof(<xsl:value-of select="$Name"/>));
        }
        
        
        // Get when datetime is After
        public static <xsl:value-of select="$Name"/>[] Get_<xsl:value-of select="PropertyName"/>_After(DateTime val) {
            ArrayList al<xsl:value-of select="$Name"/>=new ArrayList();
            try {
                using(SqlConnection sqlCon=new SqlConnection(<xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.GetDB())) {
                    sqlCon.Open();
                    using(SqlCommand sqlCom=new SqlCommand("GENSP_<xsl:value-of select="//HeaderInfo/Prefix"/>_<xsl:value-of select="$Name"/>_<xsl:value-of select="Name"/>_After",sqlCon)) {
                        sqlCom.CommandTimeout = 120;
						sqlCom.CommandType=CommandType.StoredProcedure;
                        sqlCom.Parameters.Add("@val",val);
                        using(SqlDataReader sqlDr=sqlCom.ExecuteReader()) {
                            while(sqlDr.Read()) {
                                al<xsl:value-of select="$Name"/>.Add ( getObject ( sqlDr ) );
                            }
                        }
                    
                    }
                
                    sqlCon.Close();
                }
            }
            catch(Exception ex) {
                <xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.ReportException(ex);
            }
            return (<xsl:value-of select="$Name"/>[])al<xsl:value-of select="$Name"/>.ToArray(typeof(<xsl:value-of select="$Name"/>));
        }
        
        
        // Get when datetime is Between
        public static <xsl:value-of select="$Name"/>[] Get_<xsl:value-of select="PropertyName"/>_Between(DateTime start,DateTime end) {
            ArrayList al<xsl:value-of select="$Name"/>=new ArrayList();
            try {
                using(SqlConnection sqlCon=new SqlConnection(<xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.GetDB())) {
                    sqlCon.Open();
                    using(SqlCommand sqlCom=new SqlCommand("GENSP_<xsl:value-of select="//HeaderInfo/Prefix"/>_<xsl:value-of select="$Name"/>_<xsl:value-of select="Name"/>_Between",sqlCon)) {
                        sqlCom.CommandTimeout = 120;
						sqlCom.CommandType=CommandType.StoredProcedure;
                        sqlCom.Parameters.Add("@start_",start);
                        sqlCom.Parameters.Add("@end_",end);
                        using(SqlDataReader sqlDr=sqlCom.ExecuteReader()) {
                            while(sqlDr.Read()) {
                                al<xsl:value-of select="$Name"/>.Add ( getObject ( sqlDr ) );
                            }
                        }
                    
                    }
                
                    sqlCon.Close();
                }
            }
            catch(Exception ex) {
                <xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.ReportException(ex);
            }
            return (<xsl:value-of select="$Name"/>[])al<xsl:value-of select="$Name"/>.ToArray(typeof(<xsl:value-of select="$Name"/>));
        }
        
                    </xsl:when> 
		    
		    
		    <xsl:when test="KnownClass='true'">
		    
		    
	public static <xsl:value-of select="$Name"/>[] Get_<xsl:value-of select="PropertyName"/> ( <xsl:value-of select="Type"/> obj )
	{
		return <xsl:value-of select="$Name"/>.LoadUsingSQL ( "[<xsl:value-of select="Name"/>] = '" + obj.ObjectID.ToString() + "'" );
	}
		    
		    
		    </xsl:when>

		    <xsl:when test="Type='Guid'">
	public static <xsl:value-of select="$Name"/>[] Get_<xsl:value-of select="PropertyName"/>(Guid val) 
	{
		return LoadUsingSQL ( "[<xsl:value-of select="PropertyName"/>] = '" + val.ToString() + "'" );
	}
	
	public static <xsl:value-of select="$Name"/> Get_<xsl:value-of select="PropertyName"/>_First ( Guid val )
	{
		<xsl:value-of select="$Name"/>[] vals = Get_<xsl:value-of select="PropertyName"/> ( val );
		if ( vals.Length &gt; 0 ) { return vals[0]; }
		else return null;
	}
		    
		    </xsl:when>
                    
                    <xsl:when test="Type='string' and SqlSPType!='ntext'">
                        
                        
        public static <xsl:value-of select="$Name"/>[] Get_<xsl:value-of select="PropertyName"/>(string val) {
            ArrayList al<xsl:value-of select="$Name"/>=new ArrayList();
            try {
                using(SqlConnection sqlCon=new SqlConnection(<xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.GetDB())) {
                    sqlCon.Open();
                    using(SqlCommand sqlCom=new SqlCommand("GENSP_<xsl:value-of select="//HeaderInfo/Prefix"/>_<xsl:value-of select="$Name"/>_<xsl:value-of select="Name"/>",sqlCon)) {
                        sqlCom.CommandTimeout = 120;
						sqlCom.CommandType=CommandType.StoredProcedure;
                        sqlCom.Parameters.Add("@val",val);
                        using(SqlDataReader sqlDr=sqlCom.ExecuteReader()) {
                            while(sqlDr.Read()) {
                                al<xsl:value-of select="$Name"/>.Add( getObject ( sqlDr ) );
                            }
                        }
                    
                    }
                
                    sqlCon.Close();
                }
            }
            catch(Exception ex) {
                <xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.ReportException(ex);
            }
            return (<xsl:value-of select="$Name"/>[])al<xsl:value-of select="$Name"/>.ToArray(typeof(<xsl:value-of select="$Name"/>));
        }


		public static <xsl:value-of select="$Name"/> Get_<xsl:value-of select="PropertyName"/>_First(string val) {
			<xsl:value-of select="$Name"/>[] vals = Get_<xsl:value-of select="PropertyName"/> ( val );
			if ( vals.Length > 0 ) return vals[0]; else return null;
		}
        
        
        
        
        public static <xsl:value-of select="$Name"/>[] Get_<xsl:value-of select="PropertyName"/>_Like(string val) {
            ArrayList al<xsl:value-of select="$Name"/>=new ArrayList();
            try {
                using(SqlConnection sqlCon=new SqlConnection(<xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.GetDB())) {
                    sqlCon.Open();
                    using(SqlCommand sqlCom=new SqlCommand("GENSP_<xsl:value-of select="//HeaderInfo/Prefix"/>_<xsl:value-of select="$Name"/>_<xsl:value-of select="Name"/>_Like",sqlCon)) {
                        sqlCom.CommandTimeout = 120;
						sqlCom.CommandType=CommandType.StoredProcedure;
                        sqlCom.Parameters.Add("@val",val);
                        using(SqlDataReader sqlDr=sqlCom.ExecuteReader()) {
                            while(sqlDr.Read()) {
                                al<xsl:value-of select="$Name"/>.Add ( getObject ( sqlDr ) );
                            }
                        }
                    
                    }
                
                    sqlCon.Close();
                }
            }
            catch(Exception ex) {
                <xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.ReportException(ex);
            }
            return (<xsl:value-of select="$Name"/>[])al<xsl:value-of select="$Name"/>.ToArray(typeof(<xsl:value-of select="$Name"/>));
        }   
                        
                    </xsl:when>
                    
                    <xsl:when test="Type='int'">
                        
        public static <xsl:value-of select="$Name"/>[] Get_<xsl:value-of select="PropertyName"/>(int val) {
            ArrayList al<xsl:value-of select="$Name"/>=new ArrayList();
            try {
                using(SqlConnection sqlCon=new SqlConnection(<xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.GetDB())) {
                    sqlCon.Open();
                    using(SqlCommand sqlCom=new SqlCommand("GENSP_<xsl:value-of select="//HeaderInfo/Prefix"/>_<xsl:value-of select="$Name"/>_<xsl:value-of select="Name"/>",sqlCon)) {
                        sqlCom.CommandTimeout = 120;
						sqlCom.CommandType=CommandType.StoredProcedure;
                        sqlCom.Parameters.Add("@val",val);
                        using(SqlDataReader sqlDr=sqlCom.ExecuteReader()) {
                            while(sqlDr.Read()) {
                                al<xsl:value-of select="$Name"/>.Add( getObject ( sqlDr ) );
                            }
                        }
                    
                    }
                
                    sqlCon.Close();
                }
            }
            catch(Exception ex) {
                <xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.ReportException(ex);
            }
            return (<xsl:value-of select="$Name"/>[])al<xsl:value-of select="$Name"/>.ToArray(typeof(<xsl:value-of select="$Name"/>));
        }  
        
        
        public static <xsl:value-of select="$Name"/>[] Get_<xsl:value-of select="PropertyName"/>_GreaterThan(int val) {
            ArrayList al<xsl:value-of select="$Name"/>=new ArrayList();
            try {
                using(SqlConnection sqlCon=new SqlConnection(<xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.GetDB())) {
                    sqlCon.Open();
                    using(SqlCommand sqlCom=new SqlCommand("GENSP_<xsl:value-of select="//HeaderInfo/Prefix"/>_<xsl:value-of select="$Name"/>_<xsl:value-of select="Name"/>_GreaterThan",sqlCon)) {
                        sqlCom.CommandTimeout = 120;
						sqlCom.CommandType=CommandType.StoredProcedure;
                        sqlCom.Parameters.Add("@val",val);
                        using(SqlDataReader sqlDr=sqlCom.ExecuteReader()) {
                            while(sqlDr.Read()) {
                                al<xsl:value-of select="$Name"/>.Add ( getObject ( sqlDr ) );
                            }
                        }
                    
                    }
                
                    sqlCon.Close();
                }
            }
            catch(Exception ex) {
                <xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.ReportException(ex);
            }
            return (<xsl:value-of select="$Name"/>[])al<xsl:value-of select="$Name"/>.ToArray(typeof(<xsl:value-of select="$Name"/>));
        }  
        
        
        public static <xsl:value-of select="$Name"/>[] Get_<xsl:value-of select="PropertyName"/>_LessThan(int val) {
            ArrayList al<xsl:value-of select="$Name"/>=new ArrayList();
            try {
                using(SqlConnection sqlCon=new SqlConnection(<xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.GetDB())) {
                    sqlCon.Open();
                    using(SqlCommand sqlCom=new SqlCommand("GENSP_<xsl:value-of select="//HeaderInfo/Prefix"/>_<xsl:value-of select="$Name"/>_<xsl:value-of select="Name"/>_LessThan",sqlCon)) {
                        sqlCom.CommandTimeout = 120;
						sqlCom.CommandType=CommandType.StoredProcedure;
                        sqlCom.Parameters.Add("@val",val);
                        using(SqlDataReader sqlDr=sqlCom.ExecuteReader()) {
                            while(sqlDr.Read()) {
                                al<xsl:value-of select="$Name"/>.Add ( getObject ( sqlDr ) );
                            }
                        }
                    
                    }
                
                    sqlCon.Close();
                }
            }
            catch(Exception ex) {
                <xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.ReportException(ex);
            }
            return (<xsl:value-of select="$Name"/>[])al<xsl:value-of select="$Name"/>.ToArray(typeof(<xsl:value-of select="$Name"/>));
        } 
                        
                    </xsl:when>
                    
                    
                    <xsl:when test="Type='double'">
                        
        public static <xsl:value-of select="$Name"/>[] Get_<xsl:value-of select="PropertyName"/>(double val) {
            ArrayList al<xsl:value-of select="$Name"/>=new ArrayList();
            try {
                using(SqlConnection sqlCon=new SqlConnection(<xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.GetDB())) {
                    sqlCon.Open();
                    using(SqlCommand sqlCom=new SqlCommand("GENSP_<xsl:value-of select="//HeaderInfo/Prefix"/>_<xsl:value-of select="$Name"/>_<xsl:value-of select="Name"/>",sqlCon)) {
                        sqlCom.CommandTimeout = 120;
						sqlCom.CommandType=CommandType.StoredProcedure;
                        sqlCom.Parameters.Add("@val",val);
                        using(SqlDataReader sqlDr=sqlCom.ExecuteReader()) {
                            while(sqlDr.Read()) {
                                al<xsl:value-of select="$Name"/>.Add ( getObject ( sqlDr ) );
                            }
                        }
                    
                    }
                
                    sqlCon.Close();
                }
            }
            catch(Exception ex) {
                <xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.ReportException(ex);
            }
            return (<xsl:value-of select="$Name"/>[])al<xsl:value-of select="$Name"/>.ToArray(typeof(<xsl:value-of select="$Name"/>));
        }  
        
        
        public static <xsl:value-of select="$Name"/>[] Get_<xsl:value-of select="PropertyName"/>_GreaterThan(double val) {
            ArrayList al<xsl:value-of select="$Name"/>=new ArrayList();
            try {
                using(SqlConnection sqlCon=new SqlConnection(<xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.GetDB())) {
                    sqlCon.Open();
                    using(SqlCommand sqlCom=new SqlCommand("GENSP_<xsl:value-of select="//HeaderInfo/Prefix"/>_<xsl:value-of select="$Name"/>_<xsl:value-of select="Name"/>_GreaterThan",sqlCon)) {
                        sqlCom.CommandTimeout = 120;
						sqlCom.CommandType=CommandType.StoredProcedure;
                        sqlCom.Parameters.Add("@val",val);
                        using(SqlDataReader sqlDr=sqlCom.ExecuteReader()) {
                            while(sqlDr.Read()) {
                                al<xsl:value-of select="$Name"/>.Add( getObject ( sqlDr ) );
                            }
                        }
                    
                    }
                
                    sqlCon.Close();
                }
            }
            catch(Exception ex) {
                <xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.ReportException(ex);
            }
            return (<xsl:value-of select="$Name"/>[])al<xsl:value-of select="$Name"/>.ToArray(typeof(<xsl:value-of select="$Name"/>));
        }  
        
        
        public static <xsl:value-of select="$Name"/>[] Get_<xsl:value-of select="PropertyName"/>_LessThan(double val) {
            ArrayList al<xsl:value-of select="$Name"/>=new ArrayList();
            try {
                using(SqlConnection sqlCon=new SqlConnection(<xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.GetDB())) {
                    sqlCon.Open();
                    using(SqlCommand sqlCom=new SqlCommand("GENSP_<xsl:value-of select="//HeaderInfo/Prefix"/>_<xsl:value-of select="$Name"/>_<xsl:value-of select="Name"/>_LessThan",sqlCon)) {
                        sqlCom.CommandTimeout = 120;
						sqlCom.CommandType=CommandType.StoredProcedure;
                        sqlCom.Parameters.Add("@val",val);
                        using(SqlDataReader sqlDr=sqlCom.ExecuteReader()) {
                            while(sqlDr.Read()) {
                                al<xsl:value-of select="$Name"/>.Add( getObject ( sqlDr ) );
                            }
                        }
                    
                    }
                
                    sqlCon.Close();
                }
            }
            catch(Exception ex) {
                <xsl:value-of select="//HeaderInfo/ProjectName"/>DataObject.ReportException(ex);
            }
            return (<xsl:value-of select="$Name"/>[])al<xsl:value-of select="$Name"/>.ToArray(typeof(<xsl:value-of select="$Name"/>));
        } 
                        
                    </xsl:when>                    
                </xsl:choose>
            </xsl:if>
        </xsl:for-each>
        #endif
        
        
        
        
		<xsl:apply-templates select="ClassAttribs"/>
        
        
        <xsl:if test="count(ClassAttribs/ClassAttributes[Compare='true'])=0">
        public int CompareTo(object obj) {
            return ((<xsl:value-of select="Name"/>)obj).CreatedDate.CompareTo(CreatedDate);
        }         
        </xsl:if>
		
	}

}
		
	</xsl:template>
	
	
	<xsl:template match="ClassAttribs">
		// fields and attributes of the system
#region Fields and Properties
		<xsl:apply-templates select="ClassAttributes"/>
#endregion
	</xsl:template>
	
	
	<xsl:template match="ClassAttributes">
		<xsl:if test="CType='single' and Type!='DateTime'">
		protected <xsl:value-of select="Type"/><xsl:text> </xsl:text><xsl:value-of select="Name"/><xsl:if test="Type='DateTime'">=DateTime.Now</xsl:if><xsl:if test="KnownClass='true'">=new <xsl:value-of select="Type"/>()</xsl:if><xsl:if test="Type='string'">=""</xsl:if>;
		[Sequence(<xsl:value-of select="position()"/>)]
		public <xsl:value-of select="Type"/><xsl:text> </xsl:text><xsl:value-of select="PropertyName"/> {
			<xsl:if test="KnownClass='false'">
			get { return <xsl:value-of select="Name"/>; }
			</xsl:if>
			<xsl:if test="KnownClass='true'">
			get { if ( ( <xsl:value-of select="Name"/> == null || <xsl:value-of select="Name"/>.ObjectID.Equals ( Guid.Empty ) ) &#38;&#38; !__<xsl:value-of select="Name"/>.Equals ( Guid.Empty )  ) { <xsl:value-of select="Name"/> = new <xsl:value-of select="Type"/> ( __<xsl:value-of select="Name"/> ); } return <xsl:value-of select="Name"/>; }
			</xsl:if>
			set { base.dirty=true; this.<xsl:value-of select="Name"/>=value; }
			
		}
		<xsl:if test="KnownClass='true'">
		protected Guid __<xsl:value-of select="Name"/>; // this is the guid store, we don't need to get this unless it is called
		</xsl:if>
		</xsl:if>
        
        <xsl:if test="CType='single' and Type='DateTime'">
		protected <xsl:value-of select="Type"/><xsl:text> </xsl:text><xsl:value-of select="Name"/><xsl:if test="Type='DateTime'">=DateTime.Now</xsl:if><xsl:if test="KnownClass='true'">=new <xsl:value-of select="Type"/>()</xsl:if><xsl:if test="Type='string'">=""</xsl:if>;
		[Sequence(<xsl:value-of select="position()"/>)]
		public <xsl:value-of select="Type"/><xsl:text> </xsl:text><xsl:value-of select="PropertyName"/> {
			get  { return <xsl:value-of select="Name"/>.AddMinutes ( timezoneOffset ); } 

			set 
			{ 
				base.dirty=true; 
				<xsl:value-of select="Name"/> = value;
				//this.<xsl:value-of select="Name"/>.AddMinutes ( timezoneOffset * -1 );
			}
                
		}
		
		public string<xsl:text> </xsl:text><xsl:value-of select="PropertyName"/>_Nice { get { return <xsl:value-of select="Name"/>.ToString ( "dd-MMM-yy HH:mm"); } set {} }
		
		public Int64 <xsl:value-of select="PropertyName"/>_Ticks { get { return <xsl:value-of select="Name"/>.Ticks; } set {} }
		</xsl:if>
		
		<xsl:if test="Type='double'">
		public string <xsl:value-of select="PropertyName"/>_Sep { get { return <xsl:value-of select="Name"/>.ToString ( "N" ).Split ( '.' ) [ 0 ]; } set {} }
		</xsl:if>
		
		
		<xsl:if test="ToString='true'">
		public override string ToString() { return <xsl:value-of select="Name"/>.ToString(); }
		</xsl:if>
        
        
        <xsl:if test="Compare='true'">
        public int CompareTo(object obj) {
            return ((<xsl:value-of select="/Class/Name"/>)obj).<xsl:value-of select="PropertyName"/>.CompareTo(<xsl:value-of select="Name"/>);
        }
        </xsl:if>
        
        
        

	</xsl:template>
</xsl:stylesheet>